package com.mew.slots.core.common.roller.ili;

import lombok.Data;
import lombok.ToString;

import java.lang.reflect.Method;
import java.util.HashMap;

@Data
@ToString
public class InRoom {

    String name;
    //项数
    int iarrNum;
    //共几张图
    int itemNum;
    //第几张图
    int num;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Class<? extends InRoom> c = this.getClass();
        Object inRoom = null;
        try {
            inRoom = c.newInstance();

            Method[] methods = c.getMethods();

            HashMap<String, Method> m = new HashMap<>();

            for (int i = 0; i < methods.length; i++) {
                Method method = methods[i];
                String name = method.getName();

                m.put(name,method );

            }

            for (String s : m.keySet()) {
                Method method = m.get(s);
                String name = method.getName();
                if (name.indexOf("get")>-1){
                    String set = "set" + name.replaceFirst("get", "");

                    Method setM = m.get(set);
                    if (null!=setM){
                        setM.invoke(inRoom,method.invoke(this));
                    }
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return inRoom;
    }
}
